package com.atguigu.yygh.cmn.controller;

import com.atguigu.yygh.cmn.service.DictService;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.cmn.Dict;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author wans
 * @create 2021-11-15 21:09
 */
@Api(description = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
public class DictController {
    @Autowired
    DictService service;

    //根据数据id查询子数据列表
    @ApiOperation(value = "根据数据id查询子数据列表")
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id) {
        List<Dict> list = service.findChlidData(id);
        return Result.ok(list);
    }

    @ApiOperation(value = "导出")
    @GetMapping(value = "/exportData")
    public void exportData(HttpServletResponse response) {
        service.exportData(response);
    }

    @ApiOperation(value = "导入")
    @PostMapping(value = "/importData")
    public Result importData(MultipartFile file) {
        service.importData(file);
        return Result.ok();
    }
    @ApiOperation(value = "获取数据字典名称by{dictCode}/{value}")
    @GetMapping(value = "/getName/{dictCode}/{value}")
    public String getName(@PathVariable String dictCode, @PathVariable String value) {
        String dictName = service.getDictName(dictCode, value);
        return dictName;
    }

    @ApiOperation(value = "获取数据字典名称by{value}")
    @GetMapping(value = "/getName/{value}")
    public String getName( @PathVariable String value) {
        String dictName = service.getDictName("", value);
        return dictName;
    }


}
